package com.h3c.nem.mapper;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.h3c.nem.entity.SdDept;
import com.h3c.nem.entity.TbCareInfo;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * 新员工关怀详情信息
 *
 * @author z22968
 * @date 2022/6/9 11:17
 */
public interface TbCareInfoMapper extends BaseMapper<TbCareInfo> {
    /**
     * 获取绩效优秀全部未发送的通知，并group后获取到接收通知的人
     *
     * @param sdDeptLambdaQueryWrapper
     * @return java.util.List<java.lang.String>
     * @author z22968
     * @date 2022-06-15 10:25
     */
    @Select("select old_worker_id from tb_care_info ${ew.customSqlSegment}")
    List<String> getExcellentNoticeList(@Param(Constants.WRAPPER) LambdaQueryWrapper<TbCareInfo> sdDeptLambdaQueryWrapper);

    /**
     * 获取待鼓励的人(排除鼓励过的 + 忽略的 => 即获取鼓励表中全部数据然后not in)
     *
     * @param userId
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author z22968
     * @date 2022-06-17 16:46
     */
    @Select("select saw.*,tci2.`actual_notice_time`, tci2.`type`,tci2.id as care_info_id from ( \n" +
            "   select * from tb_care_info tci where  old_worker_id = #{userId} and tci.`actual_notice_time` is not NULL and id not in ( \n" +
            "       select care_info_id from tb_care_encourage tce where tce.old_worker_id = #{userId} \n" +
            "   ) \n" +
            ") tci2 \n" +
            "join sd_all_worker saw \n" +
            "on tci2.`new_worker_id` = saw.`worker_id` order by tci2.`actual_notice_time` desc "
    )
    List<Map<String, Object>> getNonEncourageList(String userId);

    /**
     * 获取已经鼓励的人（排除忽略的）
     *
     * @param userId
     * @return java.util.List<java.util.Map < java.lang.String, java.lang.Object>>
     * @author z22968
     * @date 2022-06-28 09:34
     */
    @Select(" select saw.*,tci2.`actual_notice_time`, tci2.`type`,tci2.`tce_created_time` from ( \n" +
            "   select tci.*, tce.`created_time` as tce_created_time from tb_care_encourage tce join tb_care_info tci on tce.`care_info_id` = tci.id " +
            "   where tce.`old_worker_id` = #{userId} and tce.`ignore_flag` = 0 and tci.`actual_notice_time` is not NULL \n" +
            " ) tci2 \n" +
            " join sd_all_worker saw \n" +
            " on tci2.`new_worker_id` = saw.`worker_id`  \n" +
            " order by tci2.`tce_created_time` desc "
    )
    List<Map<String, Object>> getEncourageList(String userId);

}

